<?php
class Frontend_UserController extends Custom_Controller_Action
{
    public function loginAction()
    {
        $form = Wenda::getForm('userLogin');
        $request = $this->getRequest();
        if ($request->isPost()) {
            $formData = $request->getPost();
            if ($form->isValid($formData)) {
                $auth = Wenda::getService('authentication');
                if ($auth->authenticate($formData)) {

                    $action = $request->getParam('from');
                    Zend_Debug::dump($action);
//                    return  $this->_redirect($action);
                } else {
                    $form->setDescription(
                        $this->view->translate('login failed')
                    );
                }
            } else {
                $form->popuLate($formData);
            }
        }
        $this->view->form = $form;
    }

    public function registerAction()
    {
        $form = Wenda::getForm('userRegister');

        $request = $this->getRequest();
        if ($request->isPost()) {
            $formData = $request->getPost();
            if (Wenda::getModel('User')->register($formData)) {
                $auth = Wenda::getService('authentication');
                $auth->authenticate($formData);
                $this->_redirect("index");
            }
        }
        $this->view->form = $form;
    }

    public function logoutAction()
    {
        Wenda::getService('authentication')->clear();
        return  $this->_redirect("index");
    }
}
?>
